<template>
  <el-dialog
    title="底部导航图标"
    :visible.sync="dialogVisible"
    width="845px"
    :before-close="handleClose"
    class="material"
    style=" user-select: none;"
  >
    <div class="clearfix">
      <div
        class="img_box"
        style="background:#fff;margin:10px 22px;padding-bottom:5px;height:290px;"
      >
        <div
          v-for="(item, index) in getImgList"
          :key="index"
          class="img_item_border"
          :style="{ borderColor: item.check ? '#3587fc' : '' }"
          @click="checkHandle(index)"
        >
          <div style="width:100%;height: 36px; line-height: 36px;">
            <span>
              原始样式
            </span>
            <span style="margin-left: 14px;">
              点击样式
            </span>
          </div>
          <div>
            <img
              :src="item.src"
              alt=""
              style="width: 110px;height: 42px;margin: 10px;"
            />
          </div>
        </div>
        <div
          v-if="getImgList.length <= 0"
          style="text-align:center;margin:150px 0;"
        >
          暂无图标
        </div>
      </div>
    </div>
    <div>
      <div style="text-align:center;padding-top:10px;">
        <el-pagination
          small
          background
          layout="pager,jumper"
          :page-size="15"
          :total="listLenght"
          @current-change="changeCurrentPage"
        >
        </el-pagination>
      </div>
      <div style="text-align:right;padding-right:20px;padding-bottom:20px;">
        <el-button size="small" @click="handleClose">取 消</el-button>
        <el-button size="small" type="primary" @click="addImg">确 定</el-button>
      </div>
    </div>
    <!-- </div> -->
  </el-dialog>
</template>

<script>
import API from "@/utils/request";
export default {
  name: "NavAlert",
  props: {
    nav: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      listLenght: 0,
      group_id: "",
      dialogVisible: this.nav,
      getImgList: []
    };
  },
  watch: {
    nav(val) {
      this.dialogVisible = val;
      if (val) {
        this.changeCurrentPage();
      }
    }
  },
  created() {
    this.cont = "";
  },
  methods: {
    async changeCurrentPage(val) {
      let params = {
        page: val || 1,
        pageshow: 15
      };

      await API("wechat/Authorize/getShareIcon", params).then(
        ({ code, data }) => {
          if (code === 200) {
            if (data.length > 0) {
              this.getImgList = [];
              data.list.forEach(item => {
                this.getImgList.push({
                  src: this.$store.state.qiniu + item.file_path,
                  check: false
                });
              });

              this.listLenght = data.count;
            }
          }
        }
      );
      this.cont = "";
      this.getImgList.forEach(ele => {
        ele.check = false;
      });
    },
    handleClose() {
      this.dialogVisible = false;
      this.$emit("closeNav");
    },
    checkHandle(i) {
      if (this.cont !== "") {
        this.getImgList[this.cont].check = !this.getImgList[this.cont].check;
      }
      this.getImgList[i].check = !this.getImgList[i].check;

      this.cont = i;
    },
    addImg() {
      let list = this.getImgList.filter(item => {
        return item.check === true;
      });

      this.$emit("navTag", list);
      this.$emit("closeNav");
      this.dialogVisible = false;
    }
  }
};
</script>

<style scoped lang="scss">
.el-pagination {
  white-space: initial;
}
.currentImg {
  border: 2px solid #00ffff !important;
}
.form-select {
  width: 100px;
  transform-origin: left;
  // transform: scale(0.8);
  margin-left: 20px;
}
.form-radio {
  font-size: 12px;
  transform-origin: left;
  // transform: scale(0.8);
  // margin-left: -10px;
}
.form-inline-form {
  width: 200px;
  display: flex;
  flex-direction: row;
  align-items: top;
  justify-content: space-around;
  display: inline-block;
  margin-left: 160px;
  .form-inline-form-from {
    width: 80px;
  }
  .form-inline-form-to {
    width: 80px;
  }
}
.form-search {
  width: 200px;
  margin-left: 20px;
}
.form-input1 {
  position: relative;
  &::before {
    content: "价格";
    font-size: 12px;
    left: -49px;
    position: absolute;
  }
}
.form-input2 {
  position: relative;
  margin-left: 20px;
  &::before {
    content: "--";
    font-size: 12px;
    left: -25px;
    display: block;
    position: absolute;
    color: grey;
  }
}
.img_box {
  // position: absolute;
  // width: 96%;
  // height: 360px;
  // overflow-y: scroll;
  // display: flex;
  // flex-wrap: wrap;
  // justify-content: flex-start;
  // float: left;
  // z-index: 99;
  // margin: 5px auto;
  .img_item_border {
    float: left;
    z-index: 999999999;
    border: 1px solid rgba(grey, 0.4);
    height: 110px;
    width: 150px;
    margin: 5px 5px 0px;
    cursor: pointer;
    z-index: 99;
    border-radius: 5px;
    // display: flex;
    // align-items: center;
    img {
      width: 63px;
      height: 63px;
      // margin-top: 15%;
      border-radius: 5px;
      // border: 1px solid rgba(grey,0.4);
      // margin-left: 5px;
    }
    div {
      margin-left: 10px;
      color: rgba(grey, 0.8);
      // text-align: center;
    }
  }
}

.clearfix:before,
.clearfix:after {
  content: " ";
  display: table;
}
.clearfix:after {
  clear: both;
}
</style>
